package pkgMenu;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

public class clsConn implements Serializable{
    ResultSet res=null;
    private Connection con= null;
    Statement st=null;
    String driver="com.mysql.jdbc.Driver";
    String url="jdbc:mysql://localhost:3306/saph";
    String userDB="root";
    String passDB="";

    public clsConn(){
        conectar();
    }
    public int conectar(){
        try{
            Class.forName(driver);
        }
        catch (ClassNotFoundException e){
            System.out.println("No se pudo cargal el driver :-( "+driver);
			return -1;

        }
        try{
            con=DriverManager.getConnection(url,userDB,passDB);
        }
        catch(SQLException e){
            System.out.println("No se pudo realizar la conexion :-(");
			return -2;
        }
	return 1;
    }

    public int verificar(String sql){
        try{
            st=getCon().createStatement();
            res= st.executeQuery(sql);
            if (res.next())
                return 1;
            st.close();
        }
        catch(SQLException e){
            System.out.println(e);
        }
        return -1;
    }

    public Connection getCon() {
        return con;
    }
}